home *** CD-ROM | disk | FTP | other *** search
/ PC Pro 2005 October / DPPCPRO1005.ISO / Assets / Interface / Main.dxr / Parent Scripts_4_data.source.ls < prev    next >
Encoding:
Text File  |  2005-05-20  |  18.8 KB  |  449 lines

  1. property xmlData, xmlStatus, listData, flashObj, sectionsPage, currentBanner
  2. global dataSource, handlerStore
  3.  
  4. on new me, xmlSource, flashRef
  5.   initialise()
  6.   contentFile = getVolume() & xmlSource
  7.   if fileExists(contentFile) then
  8.     me.xmlData = new(script("xml.parser"))
  9.     me.xmlData.ignoreWhitespace(1)
  10.     me.xmlStatus = me.xmlData.parseUrl(contentFile)
  11.   else
  12.     put "file doesn't exist"
  13.   end if
  14.   if integerp(flashRef) then
  15.     flashObj = flashRef
  16.   else
  17.     put "flash reference was not an integer/sprite number"
  18.   end if
  19.   return me
  20. end
  21.  
  22. on initialise me
  23.   xmlData = VOID
  24.   xmlStatus = VOID
  25.   listData = VOID
  26. end
  27.  
  28. on getStatus me
  29.   if xmlData.doneParsing() then
  30.     if xmlData.getError() = EMPTY then
  31.       statusVal = 1
  32.     else
  33.       statusVal = -1
  34.       put xmlData.getError()
  35.     end if
  36.   else
  37.     statusVal = 0
  38.   end if
  39.   return [#status: statusVal, #parsed: xmlData.doneParsing(), #error: xmlData.getError()]
  40. end
  41.  
  42. on bannerPressed me
  43.   flashSecNum = sprite("Content pane").sections.selectedIndex + 1
  44.   bannerNode = me.findBanner(integer(flashSecNum))
  45.   launch(unescapePath(bannerNode.attributeValue["href"]))
  46. end
  47.  
  48. on findSection me, selIndex
  49.   correctedIndex = selIndex + 1
  50.   actualNumPages = xmlData["disc"]["pages"].child.count + xmlData["disc"]["sections"].child.count - 1
  51.   numSections = xmlData["disc"]["sections"].child.count
  52.   endSections = sectionsPage + numSections - 1
  53.   if correctedIndex < sectionsPage then
  54.     return xmlData["disc"]["pages"].child[selIndex + 1]
  55.   else
  56.     if correctedIndex > endSections then
  57.       actualPageNum = correctedIndex - numSections + 1
  58.       return xmlData["disc"]["pages"].child[actualPageNum]
  59.     else
  60.       actualSectionNum = correctedIndex - sectionsPage + 1
  61.       return xmlData["disc"]["sections"].child[actualSectionNum]
  62.     end if
  63.   end if
  64. end
  65.  
  66. on findBanner me, secNum
  67.   actualNumPages = xmlData["disc"]["pages"].child.count + xmlData["disc"]["sections"].child.count - 1
  68.   numSections = xmlData["disc"]["sections"].child.count
  69.   endSections = sectionsPage + numSections - 1
  70.   if secNum < sectionsPage then
  71.     return xmlData["disc"]["pages"].child[secNum]["banner"]
  72.   else
  73.     if secNum > endSections then
  74.       actualPageNum = secNum - endSections + 2
  75.       return xmlData["disc"]["pages"].child[actualPageNum]["banner"]
  76.     else
  77.       actualSectionNum = secNum - sectionsPage + 1
  78.       return xmlData["disc"]["sections"].child[actualSectionNum]["banner"]
  79.     end if
  80.   end if
  81. end
  82.  
  83. on disableHeaderBar me, secNum
  84.   secNode = me.findSection(secNum)
  85.   disabledBarColour = secNode["colours"]["row"].attributeValue["disabled"]
  86.   sprite("Header bar").color = strToRGB(disabledBarColour)
  87. end
  88.  
  89. on setBarColours me, secNum
  90.   secNode = me.findSection(secNum)
  91.   sectionColours = [#rowBase: secNode["colours"]["row"].attributeValue["base"], #rowRollOver: secNode["colours"]["row"].attributeValue["rollover"], #rowSelected: secNode["colours"]["row"].attributeValue["selected"], #rowDisabled: secNode["colours"]["row"].attributeValue["disabled"], #textBase: secNode["colours"]["text"].attributeValue["base"], #textRollOver: secNode["colours"]["text"].attributeValue["rollover"], #textSelected: secNode["colours"]["text"].attributeValue["selected"], #textDisabled: secNode["colours"]["text"].attributeValue["disabled"]]
  92.   sprite("Content pane").setListBarColour(sectionColours[#rowBase])
  93.   sprite("Footer bar2").setBarColour("normal", sectionColours[#rowBase])
  94.   sprite("Footer bar2").setBarColour("rollOver", sectionColours[#rowRollOver])
  95.   sprite("Footer bar2").setBarColour("selection", sectionColours[#rowSelected])
  96.   sprite("Footer bar2").setBarColour("disabled", sectionColours[#rowDisabled])
  97.   sprite("Footer bar2").setBarColour("textNormal", sectionColours[#textBase])
  98.   sprite("Footer bar2").setBarColour("textRollOver", sectionColours[#textRollOver])
  99.   sprite("Footer bar2").setBarColour("textSelection", sectionColours[#textSelected])
  100.   sprite("Footer bar2").setBarColour("textDisabled", sectionColours[#textDisabled])
  101.   sprite("Footer bar2").applyColours()
  102.   sprite("Fake footer").visible = 0
  103. end
  104.  
  105. on setBanner me, secNum
  106.   actualNumPages = xmlData["disc"]["pages"].child.count + xmlData["disc"]["sections"].child.count - 1
  107.   numSections = xmlData["disc"]["sections"].child.count
  108.   endSections = sectionsPage + numSections - 1
  109.   bannerNode = me.findBanner(secNum)
  110.   bannerSrc = bannerNode.attributeValue["src"]
  111.   bannerTarget = bannerNode.attributeValue["href"]
  112.   borderVis = bannerNode.attributeValue["border"]
  113.   if borderVis = "true" then
  114.     sprite("Banner border").visible = 1
  115.   else
  116.     sprite("Banner border").visible = 0
  117.   end if
  118.   bannerType = getBannerType(bannerSrc)
  119.   case bannerType of
  120.     #animGif:
  121.       member("banner_gif").fileName = getVolume() & unescapePath(bannerSrc)
  122.       sprite("Banner placeholder").member = member("banner_gif")
  123.     #flash:
  124.       member("banner_swf").fileName = getVolume() & unescapePath(bannerSrc)
  125.       member("banner_swf").scaleMode = #noScale
  126.       sprite("Banner placeholder").member = member("banner_swf")
  127.       sprite("Banner placeholder").directToStage = 1
  128.   end case
  129. end
  130.  
  131. on setColours secNum, secNode
  132.   if secNode["colours"]["row"] <> VOID then
  133.     rowColour = secNode["colours"]["row"].attributeValue["base"]
  134.     if rowColour <> VOID then
  135.       sprite("Content pane").setSectionColour(secNum, "normal", rowColour)
  136.     else
  137.       sprite("Content pane").setSectionColour(secNum, "normal", "192,192,192")
  138.     end if
  139.     rowColour = secNode["colours"]["row"].attributeValue["rollover"]
  140.     if rowColour <> VOID then
  141.       sprite("Content pane").setSectionColour(secNum, "rollOver", rowColour)
  142.     else
  143.       sprite("Content pane").setSectionColour(secNum, "rollOver", "144,144,144")
  144.     end if
  145.     rowColour = secNode["colours"]["row"].attributeValue["selected"]
  146.     if rowColour <> VOID then
  147.       sprite("Content pane").setSectionColour(secNum, "selection", rowColour)
  148.     else
  149.       sprite("Content pane").setSectionColour(secNum, "selection", "160,160,160")
  150.     end if
  151.     rowColour = secNode["colours"]["row"].attributeValue["disabled"]
  152.     if rowColour <> VOID then
  153.       sprite("Content pane").setSectionColour(secNum, "disabled", rowColour)
  154.     else
  155.       sprite("Content pane").setSectionColour(secNum, "disabled", "220,220,220")
  156.     end if
  157.   else
  158.     sprite("Content pane").setSectionColour(secNum, "normal", "192,192,192")
  159.     sprite("Content pane").setSectionColour(secNum, "rollOver", "144,144,144")
  160.     sprite("Content pane").setSectionColour(secNum, "selection", "160,160,160")
  161.     sprite("Content pane").setSectionColour(secNum, "disabled", "220,220,220")
  162.   end if
  163.   if secNode["colours"]["text"] <> VOID then
  164.     textColour = secNode["colours"]["text"].attributeValue["base"]
  165.     if textColour <> VOID then
  166.       sprite("Content pane").setSectionColour(secNum, "textNormal", textColour)
  167.     else
  168.       sprite("Content pane").setSectionColour(secNum, "textNormal", "144,144,144")
  169.     end if
  170.     textColour = secNode["colours"]["text"].attributeValue["rollover"]
  171.     if textColour <> VOID then
  172.       sprite("Content pane").setSectionColour(secNum, "textRollOver", textColour)
  173.     else
  174.       sprite("Content pane").setSectionColour(secNum, "textRollOver", "144,144,144")
  175.     end if
  176.     textColour = secNode["colours"]["text"].attributeValue["selected"]
  177.     if textColour <> VOID then
  178.       sprite("Content pane").setSectionColour(secNum, "textSelection", textColour)
  179.     else
  180.       sprite("Content pane").setSectionColour(secNum, "textSelection", "96,96,96")
  181.     end if
  182.     textColour = secNode["colours"]["text"].attributeValue["disabled"]
  183.     if textColour <> VOID then
  184.       sprite("Content pane").setSectionColour(secNum, "textDisabled", textColour)
  185.     else
  186.       sprite("Content pane").setSectionColour(secNum, "textDisabled", "192,192,192")
  187.     end if
  188.   else
  189.     sprite("Content pane").setSectionColour(secNum, "textNormal", "144,144,144")
  190.     sprite("Content pane").setSectionColour(secNum, "textRollOver", "144,144,144")
  191.     sprite("Content pane").setSectionColour(secNum, "textSelection", "96,96,96")
  192.     sprite("Content pane").setSectionColour(secNum, "textDisabled", "192,192,192")
  193.   end if
  194. end
  195.  
  196. on setContent
  197.   numPages = xmlData["disc"]["pages"].child.count
  198.   numSections = xmlData["disc"]["sections"].child.count
  199.   if numPages > 1 then
  200.     repeat with pageNum = 1 to numPages
  201.       if xmlData["disc"]["pages"].child[pageNum].attributeValue["name"] = "sections" then
  202.         sectionsPage = pageNum
  203.       end if
  204.     end repeat
  205.     if sectionsPage <> 1 then
  206.       numPreceding = sectionsPage - 1
  207.       repeat with pageNum = 1 to numPreceding
  208.         currentPage = xmlData["disc"]["pages"].child[pageNum]
  209.         sprite("Content pane").setSection(currentPage.attributeValue["name"])
  210.         if currentPage.attributeValue["headline"] <> VOID then
  211.           sprite("Content pane").setSectionAttribute(pageNum, "headline", currentPage.attributeValue["headline"])
  212.         end if
  213.         introDesc = currentPage["body"].attributeValue["text"]
  214.         if introDesc.char[1] = "<" then
  215.           sprite("Content pane").setSectionAttribute(pageNum, "maindesc", introDesc)
  216.         else
  217.           sprite("Content pane").setSectionAttribute(pageNum, "maindesc", "<pagebody>" & introDesc & "</pagebody>")
  218.         end if
  219.         setColours(pageNum, currentPage)
  220.       end repeat
  221.     end if
  222.     setSections(sectionsPage)
  223.     if sectionsPage < numPages then
  224.       sectionsOffset = 1
  225.       repeat with pageNum = sectionsPage + 1 to numPages
  226.         currentPage = xmlData["disc"]["pages"].child[pageNum]
  227.         sprite("Content pane").setSection(xmlData["disc"]["pages"].child[pageNum].attributeValue["name"])
  228.         mainDescText = currentPage["body"].attributeValue["text"]
  229.         if mainDescText.char[1] = "<" then
  230.           sprite("Content pane").setSectionAttribute(numPreceding + numSections + sectionsOffset, "maindesc", mainDescText)
  231.         else
  232.           sprite("Content pane").setSectionAttribute(numPreceding + numSections + sectionsOffset, "maindesc", "<pagebody>" & mainDescText & "</pagebody>")
  233.         end if
  234.         setColours(pageNum, currentPage)
  235.         sectionsOffset = sectionsOffset + 1
  236.       end repeat
  237.     end if
  238.   else
  239.     sectionsPage = 1
  240.     setSections(sectionsPage)
  241.   end if
  242.   repeat with sectionNum = 1 to numSections
  243.     currentSection = xmlData["disc"]["sections"].child[sectionNum]
  244.     actualSectionNum = sectionsPage + sectionNum - 1
  245.     if currentSection["intro"] <> VOID then
  246.       mainDescText = currentSection["intro"]["main"].attributeValue["text"]
  247.       if mainDescText.char[1] = "<" then
  248.         sprite("Content pane").setSectionAttribute(actualSectionNum, "maindesc", mainDescText)
  249.       else
  250.         sprite("Content pane").setSectionAttribute(actualSectionNum, "maindesc", "<pagedesc>" & mainDescText & "</pagedesc>")
  251.       end if
  252.       if currentSection["intro"]["footer"] <> VOID then
  253.         footerDescText = currentSection["intro"]["footer"].attributeValue["text"]
  254.         if footerDescText.char[1] = "<" then
  255.           sprite("Content pane").setSectionAttribute(actualSectionNum, "footerdesc", footerDescText)
  256.         else
  257.           sprite("Content pane").setSectionAttribute(actualSectionNum, "footerdesc", "<pagedesc>" & footerDescText & "</pagedesc>")
  258.         end if
  259.       end if
  260.     end if
  261.     numEntries = currentSection["entries"].child.count
  262.     repeat with entryNum = 1 to numEntries
  263.       currentEntry = currentSection["entries"].child[entryNum]
  264.       if currentEntry.attributeValue["shorttitle"] <> VOID then
  265.         listTitle = currentEntry.attributeValue["shorttitle"]
  266.         fullTitle = currentEntry.attributeValue["title"]
  267.         sprite("Content pane").setApp(actualSectionNum, listTitle, fullTitle)
  268.       else
  269.         sprite("Content pane").setApp(actualSectionNum, currentEntry.attributeValue["title"])
  270.       end if
  271.       descText = currentEntry["description"].attributeValue["text"]
  272.       sprite("Content pane").setAppAttribute(actualSectionNum, entryNum, "description", descText)
  273.       numLinks = currentEntry["links"].child.count
  274.       repeat with linkNum = 1 to numLinks
  275.         setLink(actualSectionNum, entryNum, linkNum, currentEntry["links"].child[linkNum])
  276.       end repeat
  277.       if currentEntry["footer"] <> VOID then
  278.         column1Title = VOID
  279.         column1Text = VOID
  280.         column2Title = VOID
  281.         column2Text = VOID
  282.         if currentEntry["footer"]["column1"] <> VOID then
  283.           currentColumn = currentEntry["footer"]["column1"]
  284.           column1Title = "<columnboldwhite>" & currentColumn.attributeValue["name"] & "</columnboldwhite>"
  285.           column1Text = "<column>" & currentColumn.child[1].attributeValue["text"]
  286.           numRows = currentColumn.child.count
  287.           if numRows > 1 then
  288.             repeat with rowNum = 2 to currentColumn.child.count
  289.               rowText = currentColumn.child[rowNum].attributeValue["text"]
  290.               column1Text = column1Text & " " & rowText
  291.             end repeat
  292.           end if
  293.           column1Texlt = column1Text & "</column>"
  294.           sprite("Content pane").setAppAttribute(actualSectionNum, entryNum, "column1", column1Text)
  295.           sprite("Content pane").setAppAttribute(actualSectionNum, entryNum, "column1Title", column1Title)
  296.           sprite("Content pane").setAppAttribute(actualSectionNum, entryNum, "column1Groups", currentColumn.child.count)
  297.         end if
  298.         if currentEntry["footer"]["column2"] <> VOID then
  299.           currentColumn = currentEntry["footer"]["column2"]
  300.           column2Title = "<columnboldwhite>" & currentColumn.attributeValue["name"] & "</columnboldwhite>"
  301.           column2Text = "<column>" & currentColumn.child[1].attributeValue["text"]
  302.           numRows = currentColumn.child.count
  303.           if numRows > 1 then
  304.             repeat with rowNum = 2 to currentColumn.child.count
  305.               rowText = currentColumn.child[rowNum].attributeValue["text"]
  306.               column2Text = column2Text & " " & rowText
  307.             end repeat
  308.           end if
  309.           column2Text = column2Text & "</column>"
  310.           sprite("Content pane").setAppAttribute(actualSectionNum, entryNum, "column2", column2Text)
  311.           sprite("Content pane").setAppAttribute(actualSectionNum, entryNum, "column2Title", column2Title)
  312.           sprite("Content pane").setAppAttribute(actualSectionNum, entryNum, "column2Groups", currentColumn.child.count)
  313.         end if
  314.       end if
  315.     end repeat
  316.   end repeat
  317.   if xmlData["disc"]["footer"] <> VOID then
  318.     numFooterPages = xmlData["disc"]["footer"].child.count
  319.     footerPages = xmlData["disc"]["footer"]
  320.     repeat with footerPage = 1 to numFooterPages
  321.       if footerPages.child[footerPage].attributeValue["text"] <> VOID then
  322.         sprite("Content pane").setFooterPage(footerPages.child[footerPage].attributeValue["name"], footerPages.child[footerPage].attributeValue["text"])
  323.         next repeat
  324.       end if
  325.       if footerPages.child[footerPage].attributeValue["href"] <> VOID then
  326.         sprite("Content pane").setFooterPage(footerPages.child[footerPage].attributeValue["name"], footerPages.child[footerPage].attributeValue["href"])
  327.       end if
  328.     end repeat
  329.   end if
  330.   sprite("Content pane").contentDone()
  331. end
  332.  
  333. on showFooterPage me, pageNum
  334.   if pageNum = 5 then
  335.     dataSource.setBanner(1)
  336.     sprite("Content pane").showCredits()
  337.   else
  338.     if xmlData["disc"]["footer"] <> VOID then
  339.       if pageNum <> 1 then
  340.         dataSource.setBanner(1)
  341.       end if
  342.       footerPage = xmlData["disc"]["footer"].child[pageNum]
  343.       pageTitle = footerPage.attributeValue["name"]
  344.       if footerPage.attributeValue["text"] <> VOID then
  345.         sprite("Content pane").showPage(pageTitle, footerPage.attributeValue["text"])
  346.       else
  347.         if footerPage.attributeValue["href"] <> VOID then
  348.           launch(unescapePath(footerPage.attributeValue["href"]))
  349.         else
  350.           pageText = "Page not recognised"
  351.         end if
  352.       end if
  353.     end if
  354.   end if
  355. end
  356.  
  357. on setSections sectionsPage
  358.   numSections = xmlData["disc"]["sections"].child.count
  359.   repeat with pageNum = 1 to numSections
  360.     currentSection = xmlData["disc"]["sections"].child[pageNum]
  361.     sprite("Content pane").setSection(currentSection.attributeValue["name"])
  362.     if currentSection["intro"] <> VOID then
  363.       setSectionIntro(sectionsPage + pageNum - 1, currentSection)
  364.     end if
  365.     setColours(sectionsPage + pageNum - 1, currentSection)
  366.   end repeat
  367. end
  368.  
  369. on setSectionIntro secNum, section
  370.   if section.attributeValue["shorttitle"] <> VOID then
  371.     shortTitle = section.attributeValue["shorttitle"]
  372.   end if
  373.   introDesc = removeOuterTags(section["intro"]["main"].toString())
  374.   if section["intro"]["footer"] <> VOID then
  375.     footerDesc = removeOuterTags(section["intro"]["footer"].toString())
  376.   else
  377.     footerDesc = VOID
  378.   end if
  379.   highlights = findNodesWithAttr(section["entries"], "highlight", "true")
  380.   if highlights.count <> 0 then
  381.     setHighlights(secNum, highlights)
  382.   end if
  383.   updates = findNodesWithAttr(section["entries"], "updated", "true")
  384.   if updates.count <> 0 then
  385.     setUpdates(secNum, updates)
  386.   end if
  387. end
  388.  
  389. on setHighlights secNum, highlights
  390.   repeat with hlNum = 1 to highlights.count
  391.     if highlights[hlNum].node.attributeValue["shorttitle"] <> VOID then
  392.       hlTitle = highlights[hlNum].node.attributeValue["shorttitle"]
  393.     else
  394.       hlTitle = highlights[hlNum].node.attributeValue["title"]
  395.     end if
  396.     if highlights[hlNum].node["highlight"] <> VOID then
  397.       hlDesc = highlights[hlNum].node["highlight"].attributeValue["text"]
  398.       if highlights[hlNum].node["highlight"].attributeValue["image"] <> VOID then
  399.         hlImage = getVolume() & "\" & highlights[hlNum].node["highlight"].attributeValue["image"]
  400.       else
  401.         hlImage = "undefined"
  402.       end if
  403.     else
  404.       hlDesc = "ERROR: A highlight description was not provided for this item."
  405.       hlImage = "none"
  406.     end if
  407.     sprite("Content pane").setHighlight(secNum, hlNum, hlTitle, hlDesc, highlights[hlNum].childNum, hlImage)
  408.   end repeat
  409. end
  410.  
  411. on setUpdates secNum, updates
  412.   repeat with updNum = 1 to updates.count
  413.     sprite("Content pane").setUpdate(secNum, updates[updNum].childNum, updates[updNum].node.attributeValue["title"])
  414.   end repeat
  415. end
  416.  
  417. on findNodesWithAttr parentNode, attrName, attrValue
  418.   matchingNodes = []
  419.   repeat with childNum = 1 to parentNode.child.count
  420.     currentNode = parentNode.child[childNum]
  421.     if currentNode.attributeValue[attrName] = attrValue then
  422.       matchingNodes.add([#node: currentNode, #childNum: childNum])
  423.     end if
  424.   end repeat
  425.   return matchingNodes
  426. end
  427.  
  428. on assembleHTMLText parentNode
  429.   htmlText = EMPTY
  430.   repeat with childNum = 1 to parentNode.child.count
  431.     htmlText = htmlText & parentNode.child[childNum].toString()
  432.   end repeat
  433.   return htmlText
  434. end
  435.  
  436. on removeOuterTags xmlString
  437.   tagLength = offset(">", xmlString)
  438.   returnStr = xmlString.char[tagLength + 1..xmlString.length - tagLength - 1]
  439.   return returnStr
  440. end
  441.  
  442. on setLink sectionNum, entryNum, linkNum, currentLink
  443.   if currentLink.child.count <> 0 then
  444.     sprite("Content pane").setComplexLink(sectionNum, entryNum, linkNum, currentLink.attributeValue["label"])
  445.   else
  446.     sprite("Content pane").setSimpleLink(sectionNum, entryNum, currentLink.attributeValue["label"], currentLink.attributeValue["href"])
  447.   end if
  448. end
  449.